<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{$title}</title>
<link rel="stylesheet" type="text/css" href="Res/index/css/Iframe.css" />
<link rel="stylesheet" href="Res/index/utilLib/bootstrap.min.css" type="text/css" media="screen" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<script type="text/javascript" src="Res/js/jquery-1.8.3.min.js"></script>
</head>

<body>
<span class="cp_title">系统管理－代码添加</span>
<div class="add_cp">
	<a href="index.php?c=code&m=view">返回代码列表</a>
</div>
<div class="table_con" style="margin: 0 auto;text-align: center;">
    <form class="form-horizontal" role="form" action="index.php?c=code&m=new_create" method="post">
    <div class="form-group">
        <label class="col-sm-2 control-label">代码名称：</label>
        <div class="col-sm-5">
            <input type="text"  autocomplete="off" value="{$cookie.code_name}" class="form-control" id="code_name" name="code_name" placeholder="代码名称" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">用户名：</label>
        <div class="col-sm-5">
            <select id="user_id" name="user_id" class="form-control">
                <option value="0">选择用户名称</option>
                {foreach from=$user_list item=row}                                   
                    {if $cookie.user_id == $row.user_id}
                    <option value="{$row.user_id}" selected="true">{$row.user_name}</option>                    
                    {else}
                    <option value="{$row.user_id}">{$row.user_name}</option>
                    {/if}
                {/foreach}
            </select>
        </div>
    </div>
    
    <div class="form-group">
        <label class="col-sm-2 control-label">代码签名：</label>
        <div class="col-sm-5">
            <input type="text"  autocomplete="off" value="{$appid}" readonly="true" class="form-control" id="appid" name="appid" placeholder="代码签名" />
        </div>
    </div>
        
    <div class="form-group">
        <label class="col-sm-2 control-label">通信密鑰：</label>
        <div class="col-sm-5">
            <input type="text"  autocomplete="off" value="{$appkey}"  readonly="true" class="form-control" id="appkey" name="appkey" placeholder="通信密鑰" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">生成代码URL：</label>
        <div class="col-sm-5">
            <input type="button" id="btn_create_url_php" class="btn btn-success" value="点击生成PHP应用代码" />
            <input type="button" id="btn_create_url_js" class="btn btn-success" value="点击生成JS应用代码" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">代码URL：</label>
        <div class="col-sm-4">
            <input type="text" readonly="true" autocomplete="off" value="{$cookie.code_url}" class="form-control" id="code_url" name="code_url" placeholder="代码URL" />
        </div>
        <div class="col-sm-1">
            <input type="button" value="測試" id="btn_test_id" class="btn btn-primary" />
        </div>
    </div>    
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-5">
            <input type="hidden" value="{$token}" name="token" />
            <button type="submit" class="btn btn-primary btn-lg btn-block">新增</button>            
        </div>
    </div>
    </form>
</div>
{literal}
<script>    
$(function(){
    $("#btn_create_url_php").click(function(){
        var host = window.location.host;
        var appid = $("#appid").val();
        if(appid === '') {
            alert("刷新頁面，再點擊");
            return;
        }
        var url = 'http://' + host + '/in.php?c=in&m=php&appid=' + appid;
        $("#code_url").val(url);
    });
    $("#btn_create_url_js").click(function(){
        var host = window.location.host;
        var appid = $("#appid").val();
        if(appid === '') {
            alert("刷新頁面，再點擊");
            return;
        }
        var url = 'http://' + host + '/in.php?c=in&m=js&appid=' + appid;
        $("#code_url").val(url);
    });
    $("#btn_test_id").click(function(){
        var url = $("#code_url").val();
        if(url !== "") {
            var obj = new Object();
            obj.test = 1;
            obj.ajax = 1;
            $.post(url, obj, function(data){
                if(data === 'ok') {
                    alert("測試成功<" + data + ">");
                } else {
                    alert("測試失敗，檢查url是否正確，將代碼url復制瀏覽器手動測試");
                }
            }, "text");
        } else {
            alert("點擊生成代碼");
        }
    });
});
</script>
{/literal}
</script>
</body>
</html>

